<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
  xmlns:s="http://jboss.org/schema/seam/taglib">

<ui:composition template="../WEB-INF/template/template_2x.xhtml">
  <!-- disabled since it doesn't create the HPerson to go with the HAccount
      <ui:define name="right_content">
          <s:link action="#{userAction.createUser}"
            rendered="#{s:hasPermission('seam.account', 'create')}"
            value="#{msgs['jsf.CreateNewUser']}"/>
      </ui:define>
   -->

  <ui:define name="page_title">#{msgs['jsf.ManageUsers']}</ui:define>
  <ui:define name="center_content">
    <script type="text/javascript">
      function confirmDelete() {
        return confirm("#{msgs['jsf.AreYouSureYouWishToDeleteThisUserThisActionCannotBeUndone']}");
      }

      function focusUserFilterInput() {
        #{rich:element('username_filter_input')}
      .
        focus();
      }
    </script>
    <a4j:jsFunction name="editUser" action="#{userAction.editUser(username)}">
      <a4j:param name="val1" assignTo="#{username}"/>
    </a4j:jsFunction>
    <a4j:jsFunction name="deleteUser" action="#{userAction.deleteUser(username)}" render="usermanagerForm">
      <a4j:param name="val1" assignTo="#{username}"/>
    </a4j:jsFunction>

    <h:form id="usermanagerForm">
      <s:token allowMultiplePosts="true"/>

      <div style="text-align: center">
        <rich:dataScroller renderIfSinglePage="false" for="userList"
          maxPages="100" page="#{userAction.userPagedListDataModel.scrollerPage}"
          id="scroller" fastControls="hide" render="scroller2" >
          <f:facet name="first">
            <h:outputText value="" styleClass="icon-to-start"/>
          </f:facet>
          <f:facet name="previous">
            <h:outputText value="" styleClass="icon-left-open"/>
          </f:facet>
          <f:facet name="next">
            <h:outputText value="" styleClass="icon-right-open-1"/>
          </f:facet>
          <f:facet name="fastforward">
            <h:outputText value="" styleClass="icon-fast-fw-1"/>
          </f:facet>
          <f:facet name="last">
            <h:outputText value="" styleClass="icon-to-end"/>
          </f:facet>
          <f:facet name="first_disabled">
            <h:outputText value="" styleClass="icon-to-start"/>
          </f:facet>
          <f:facet name="previous_disabled">
            <h:outputText value="" styleClass="icon-left-open"/>
          </f:facet>
          <f:facet name="next_disabled">
            <h:outputText value="" styleClass="icon-right-open-1"/>
          </f:facet>
          <f:facet name="fastforward_disabled">
            <h:outputText value="" styleClass="icon-fast-fw-1"/>
          </f:facet>
          <f:facet name="last_disabled">
            <h:outputText value="" styleClass="icon-to-end"/>
          </f:facet>
        </rich:dataScroller>
      </div>

      <rich:dataTable id="userList" cellspacing="0" styleClass="fullwidth"
        value="#{userAction.userPagedListDataModel}" var="user"
        rows="#{userAction.userPagedListDataModel.pageSize}"
        columnClasses="centered,centered,centered,centered">
        <rich:column width="auto">
          <f:facet name="header">
            <h:panelGroup>
              <h:outputText value="#{msgs['jsf.Username']}"/>
              <br/>
              <h:inputText id="username_filter_input" onkeydown="if(event.keyCode == 13) {return false}"
                value="#{userAction.userPagedListDataModel.filter}"
                styleClass="filter_input">
                <a4j:ajax event="keyup" render="userList"
                  oncomplete="focusUserFilterInput()">
                  <a4j:attachQueue ignoreDupResponses="true"
                    requestDelay="700"/>
                </a4j:ajax>
              </h:inputText>
            </h:panelGroup>
          </f:facet>
          #{user}
        </rich:column>
        <h:column width="auto">
          <f:facet name="header">#{msgs['jsf.Email']}</f:facet>
          #{userAction.getEmail(user)}
        </h:column>
        <h:column width="auto">
          <f:facet name="header">#{msgs['jsf.MemberOf']}</f:facet>
          #{userSearch.getUserRoles(user)}
        </h:column>
        <h:column width="auto">
          <f:facet name="header">#{msgs['jsf.Enabled']}</f:facet>
          <span
            class="#{identityManager.isUserEnabled(user) ? 'icon-ok checkmark' : 'icon-remove cross'}"/>
        </h:column>
        <h:column width="100px">
          <f:facet name="header">#{msgs['jsf.Actions']}</f:facet>
          <s:fragment rendered="#{s:hasPermission('seam.user', 'update')}">
            <button onclick="editUser('#{user}');return false">
              #{msgs['jsf.Edit']}
            </button>
          </s:fragment>
          <s:fragment rendered="#{s:hasPermission('seam.user', 'delete')}">
            <button onclick="if(confirmDelete()){deleteUser('#{user}')};return false;">
              #{msgs['jsf.Delete']}
            </button>
          </s:fragment>
        </h:column>
      </rich:dataTable>

      <div style="text-align: center">
        <rich:dataScroller renderIfSinglePage="false" for="userList"
          page="#{userAction.userPagedListDataModel.scrollerPage}"
          maxPages="100" id="scroller2" render="scroller" fastControls="hide">
          <f:facet name="first">
            <h:outputText value="" styleClass="icon-to-start"/>
          </f:facet>
          <f:facet name="previous">
            <h:outputText value="" styleClass="icon-left-open"/>
          </f:facet>
          <f:facet name="next">
            <h:outputText value="" styleClass="icon-right-open-1"/>
          </f:facet>
          <f:facet name="fastforward">
            <h:outputText value="" styleClass="icon-fast-fw-1"/>
          </f:facet>
          <f:facet name="last">
            <h:outputText value="" styleClass="icon-to-end"/>
          </f:facet>
          <f:facet name="first_disabled">
            <h:outputText value="" styleClass="icon-to-start"/>
          </f:facet>
          <f:facet name="previous_disabled">
            <h:outputText value="" styleClass="icon-left-open"/>
          </f:facet>
          <f:facet name="next_disabled">
            <h:outputText value="" styleClass="icon-right-open-1"/>
          </f:facet>
          <f:facet name="fastforward_disabled">
            <h:outputText value="" styleClass="icon-fast-fw-1"/>
          </f:facet>
          <f:facet name="last_disabled">
            <h:outputText value="" styleClass="icon-to-end"/>
          </f:facet>
        </rich:dataScroller>
      </div>

    </h:form>
  </ui:define>

</ui:composition>
</html>
